/********************************** (C) COPYRIGHT *********************************
 * File Name          : CH392.H
 * Author             : WCH
 * Version            : V1.1
 * Date               : 2022/12/28
 * Description        : CH392 structure description
 **********************************************************************************/
#ifndef __CH392_H__
#define __CH392_H__

#include "stdio.h"
#include "string.h"
#include "CH392INC.H"
#include "CH392CMD.H"

#define TCP_CLIENT_MODE 0
#define TCP_SERVER_MODE 1

struct _CH392_SYS
{
    UINT8 IPAddr[4];        /* CH392 IP addr 32bit*/
    UINT8 GWIPAddr[4];      /* CH392 GW IP addr 32bit*/
    UINT8 MASKAddr[4];      /* CH392 MASK addr 32bit*/
    UINT8 MacAddr[6];       /* CH392 MAC addr 48bit*/
    UINT8 PHYStat;          /* CH392 PHY state 8bit*/
    UINT8 IntfMode;         /* Interface mode */
    UINT8 UnreachIPAddr[4]; /* Unreachable IP */
    UINT16 UnreachPort;     /* Unreachable Port */
};

struct _SOCK_INF
{
    UINT8 IPAddr[4];  /* Socket des IP addr 32bit*/
    UINT8 ProtoType;  /* Proto type */
    UINT8 ScokStatus; /* Socket status */
    UINT8 TcpMode;    /* TCP mode */
    UINT16 DesPort;   /* DesPort */
    UINT16 SourPort;  /* SourPort */
    UINT16 SendLen;   /* Send date len */
    UINT16 RemLen;    /* Remain len */
    UINT8 *pSend;     /* Send point */
};

void mStopIfError(UINT8 iError);
void InitCH392InfParam(void);
void InitSocket0Param(void);
void CH392Socket0InitOpen(void);
void keeplive_set(void);
void CH392SocketInterrupt(UINT8 sockindex);
void CH392GlobalInterrupt(void);
UINT8 CH392Init(void);
void InitSocket1Param(void);
void CH392Socket1InitOpen(void);

#endif
